/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tv.venta.dao;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.Query;
import tv.global.dao.BaseDAO;
import tv.venta.modelo.Cliente;
import tv.venta.modelo.CondicionDePago;

/**
 *
 * @author Claudio
 */
@Stateless
@LocalBean
public class CondicionDePagoDAO extends BaseDAO implements Serializable{

    public List<CondicionDePago> getCondicionesDePago(Map<String,String> filtro){

        try {

            String sQuery = "SELECT c FROM CondicionDePago c ";
            sQuery += generarStringFiltro(filtro,"c", true);
            sQuery += " ORDER BY c.cndpag";

//            System.err.println(sQuery);

            Query q = getEntityManager().createQuery(sQuery);

            q.setMaxResults(50);
            return q.getResultList();

        } catch (Exception e) {
            
            System.err.println("Error al consultar CondicionDePago");
            e.printStackTrace();
            return new ArrayList<CondicionDePago>();
        }


    }

    public CondicionDePago getCondicionDePago(Map<String, String> filtro) {

        try {
            String sQuery = "SELECT c FROM CondicionDePago c ";
            sQuery += generarStringFiltro(filtro,"c", true);
            sQuery += " ORDER BY c.cndpag";

            Query q = getEntityManager().createQuery(sQuery);

            return (CondicionDePago) q.getSingleResult();

        } catch (Exception e) {

            System.err.println("Error al consultar CondicionDePago");
            e.printStackTrace();
            return null;
        }

    }
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
}
